/**
 * @Title: ThemeListController.java
 * @Package com.zll.ccp.controller.forum
 * @author zhanglinlu
 * @date 2019年5月30日 下午4:21:40
 */
package com.zll.ccp.controller.forum;

import javax.servlet.http.HttpSession;

import com.zll.ccp.annotation.RequireOwn;
import com.zll.ccp.model.pojo.ResourceType;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.zll.ccp.model.forum.Theme;
import com.zll.ccp.service.forum.IForumService;
import com.zll.ccp.utils.CommonUtils;

/**
 * @ClassName: ThemeListController
 * @Description: 主题controller
 * @author zhanglinlu
 * @date 2019年5月30日 下午4:21:40
 * 
 */
@Controller
public class ThemeListController {

    @Autowired
    private IForumService forumService;

    /**
     * @Title: themelist
     * @Description: 进入主提列表
     * @return
     */
    @GetMapping("/themelist")
    public String themelist() {
        return "forum/themelist";
    }

    /**
     * @Title: getTableData
     * @Description: 获取主题列表数据
     * @param pName 主题名
     * @param pCT 创建时间
     * @return
     */
    @GetMapping("/themelistdata")
    @ResponseBody
    public Object getTableData(String pName, Long pCT) {
        if (StringUtils.isBlank(pName)) {
            pName = null;
        }
        String ct = null;
        if (pCT != 0) {
            ct = DateFormatUtils.format(pCT, "yyyy-MM-dd");
        }
        return forumService.getThemeList(pName, ct);
    }

    /**
     * @Title: addtheme
     * @Description: 增加主题
     * @param name 主题名
     * @return
     */
    @GetMapping("/addtheme")
    @ResponseBody
    public Object addtheme(String name, HttpSession session) {
        Theme theme = new Theme();
        theme.setId(CommonUtils.getUUID());
        theme.setCreatetime(CommonUtils.getNowDate());
        theme.setName(name);
        theme.setUserid(session.getAttribute("userId").toString());
        forumService.addTheme(theme);
        return null;
    }

    /**
     * @Title: deleteTheme
     * @Description: 删除主题
     * @param 主键id
     * @return
     */
    @RequireOwn(resourceType = ResourceType.theme,paramName = "id")
    @GetMapping("/deletetheme")
    @ResponseBody
    public Object deleteTheme(String id) {
        forumService.deleteThemeById(id);
        return null;
    }
}
